<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>添加地区</title>
    <link rel="stylesheet" href="/static/layui/css/layui.css">
</head>
<body class="layui-layout-body">
<div class="layui-layout layui-layout-admin">
    <div style="padding: 0 15px;">
        <fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;">
            <legend>添加</legend>
        </fieldset>

        <form class="layui-form" action="">
            <div class="layui-form-item">
                <label class="layui-form-label">地区</label>
                <div class="layui-input-inline">
                    <input type="text" name="name" lay-verify="required" autocomplete="off"
                           placeholder="请输入地区"
                           class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" lay-submit="" lay-filter="addSubmit" style="border-radius: 5px;">立即提交
                    </button>
                </div>
            </div>
        </form>
    </div>
</div>
<script src="/static/layui/layui.js"></script>
<script src="https://code.jquery.com/jquery-3.4.1.min.js"></script>

<script>
    layui.use(['form'], function () {
        var form = layui.form

        //监听提交
        form.on('submit(addSubmit)', function (data) {
            $.post("/area/addSubmit",JSON.stringify(data.field),function (e) {
                if (e.errno == 1) {
                            layer.msg(e.errmsg, {
                                time: 1000,
                                end: function () {
                                    window.parent.location.reload();
                                    var index = parent.layer.getFrameIndex(window.name);
                                    parent.layer.close(index);
                                }
                            });
                        } else {
                            layer.msg(e.errmsg);
                        }
            })
            return false;
        });
    })
</script>
</body>
</html>